package com.wdress.util;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	//private static final SessionFactory sessionFactory_fr;
	//private static final SessionFactory sessionFactory_es;
	
	static {
		try {
			sessionFactory = new Configuration().configure().buildSessionFactory();
			//sessionFactory_fr = new Configuration().configure("/hotelfr.cfg.xml").buildSessionFactory();
			//sessionFactory_es = new Configuration().configure("/hoteles.cfg.xml").buildSessionFactory();
		}
		catch(Throwable t ){
			System.err.println("Initial SessionFacotyr createion failed."+t);
			throw new ExceptionInInitializerError(t);
		}
	}
	
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	public static SessionFactory getSessionFactory(HttpServletRequest arg2) {
		return sessionFactory;
	}
	
//	public static SessionFactory getSessionFactory(HttpServletRequest arg2) {
//		String hostName = arg2.getServerName();
//		if(hostName==null||hostName.equals("")||hostName.equals("www.hotelsorting.com")||hostName.equals("hotelsorting.com")){
//		    return sessionFactory;
//		}
//		if(hostName.equals("www.hotelsorting.fr")||hostName.equals("hotelsorting.fr")){
//	        return sessionFactory;
//	    }
//		if(hostName.equals("www.hotelsorting.es")||hostName.equals("hotelsorting.es")){
//	        return sessionFactory_es;
//	    }
//		return sessionFactory;
//	}

}
